package qjc.n_贪心算法;

public class n3_跳跃游戏II {
    public int jump(int[] nums) {
        int n = nums.length;
        if (n <= 1) {
            return 0;
        }
        int jum = 0;
        int currentEnd = 0;
        int farthest = 0;
        for (int i = 0; i < n - 1; i++) {
            farthest = Math.max(farthest, nums[i] + i);
            if (i == currentEnd) {
                currentEnd = farthest;
                jum++;
                if (currentEnd >= n - 1) {
                    break;
                }
            }
        }
        return jum;
    }
}
